import com.huaweicloud.sdk.iot.device.client.requests.CommandRsp;
import com.huaweicloud.sdk.iot.device.service.AbstractService;
import com.huaweicloud.sdk.iot.device.service.DeviceCommand;
import com.huaweicloud.sdk.iot.device.service.Property;

import java.util.Map;
import java.util.Random;

public class Led extends AbstractService {

    //按照设备模型定义属性，注意属性的name和类型需要和模型一致，writeable表示属性知否可写，name指定属性名
    @Property(name = "led01", writeable = true)                  //可读true
            int led01 = 1;

    public int getLed01() {
        led01 = new Random().nextInt(100);
        return led01;
    }

    public void setLed01(int led01) {
        this.led01 = led01;
    }


    public int getLed02() {
        led02 = new Random().nextInt(100);
        return led02;
    }

    public void setLed02(int led02) {
        this.led02 = led02;
    }

    @Property(name = "led02", writeable = true)    //不可读false
    int led02 = 1;

    public int getLed03() {
        return led03;
    }

    public void setLed03(int led03) {
        this.led03 = led03;
    }

    @Property(name = "led03", writeable = true)                  //可读true
    int led03 = 1;

    public int getLed04() {
        return led04;
    }

    public void setLed04(int led04) {
        this.led04 = led04;
    }

    @Property(name = "led04", writeable = true)                  //可读true
    int led04 = 1;

    public int getLed05() {
        return led05;
    }

    public void setLed05(int led05) {
        this.led05 = led05;
    }

    @Property(name = "led05", writeable = true)                  //可读true
    int led05 = 1;



    //定义命令，注意接口入参和返回值类型是固定的不能修改，否则会出现运行时错误
    @DeviceCommand(name = "switch")
    public CommandRsp alarm(Map<String, Object> paras) {
        boolean switch_led01 = (boolean) paras.get("switch_led01");
        boolean switch_led02 = (boolean) paras.get("switch_led02");
        boolean switch_led03 = (boolean) paras.get("switch_led03");
        boolean switch_led04 = (boolean) paras.get("switch_led04");
        boolean switch_led05 = (boolean) paras.get("switch_led05");


        System.out.println("switch  switch_led01 = " + switch_led01);
        System.out.println("switch  switch_led02 = " + switch_led02);
        System.out.println("switch  switch_led03 = " + switch_led03);
        System.out.println("switch  switch_led04 = " + switch_led04);
        System.out.println("switch  switch_led05 = " + switch_led05);

        //将log换成System.out.println
        CommandRsp commandRsp = new CommandRsp(0);
        commandRsp.setResponseName("COMMAND_RESPONSE");
        //定制
        return commandRsp;
    }


}